import axios from "~/http/request"
import useFilePwd from "~/composables/file/useFilePwd";
let { getPathPwd } = useFilePwd();

// 新建文件夹
export const newFolderReq = (data) => {
	data.password = getPathPwd(data.path);
	return axios({
		url: `/rpan-storage/api/file/operator/mkdir`,
		method: "post",
		data
	})

}
// 批量删除文件/文件夹
export const batchDeleteReq = (data) => {
	return axios({
		url: `/rpan-storage/api/file/operator/delete/batch`,
		method: "post",
		data
	})
}


// 重命名文件
export const renameFileReq = (data) => {
	data.password = getPathPwd(data.path);
	return axios({
		url: `/rpan-storage/api/file/operator/rename/file`,
		method: "post",
		data
	})
}

// 重命名文件夹
export const renameFolderReq = (data) => {
	data.password = getPathPwd(data.path);
	return axios({
		url: `/rpan-storage/api/file/operator/rename/folder`,
		method: "post",
		data
	})
}

// 获取文件上传链接
export const uploadFileReq = (data) => {
	data.password = getPathPwd(data.path);
	const formData = new FormData();
	// formData.append("storageKey", data.storageKey)
	formData.append('file', data.file);
	formData.append('fileMD5', data.fileMD5);
	formData.append('fileSize', data.fileSize);
	formData.append('totalChunks', data.totalChunks);
	formData.append('currChunks', data.currChunks);
	return axios({
		url: `/zuul/rpan-storage/api/file/operator/upload/file`,
		method: "post",
		data: formData,
		config: {
			headers: {
				"Content-Type": "multipart/form-data"
      },
      onUploadProgress: data.onUploadProgress
		}

	})
}
